<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">

    <p id="content"></p>

</div>
</body>
<script src="js/vue3.js"></script>

<script type="text/javascript">

    function reactive(obj) {
        return new Proxy(obj, {
            get(target, p, receiver) {
                return Reflect.get(target, p, receiver);
            },
            set(target, p, value, receiver) {
                Reflect.set(target, p, value, receiver);
                console.log('数据变化了，视图自动更新');
                effect();
                return true;

            }
        });
    }

    const state = reactive({
        id: 12,
        name: 'andy',
        get value() {
            return this.name;
        }
    });

    function effect() {
        document.querySelector('#content').innerText = state.name;
    }

    effect();

    setInterval(() => {
        state.name += Math.random();

    }, 1000);


</script>

</html>
